package com.chenc.unitdemo.jwt.golbal;

import javax.servlet.http.HttpServletResponse;

/**
 * @Author: dyhu
 * @Date: 2021/3/4 13:38
 */
public class ControllerBase {
    /**
     * 执行成功
     * @return
     */
    protected Result ok() {
        return Result.success();
    }

    /**
     * 执行成功并返回数据
     * @param data
     * @param <T>
     * @return
     */
    protected <T> Result<T> ok(T data) {
        return Result.success(data);
    }

    /**
     * 返回404
     * @return
     */
    protected Result notFound() {
        return Result.nothing();
    }

    /**
     * 参数错误
     * @return
     */
    protected Result badRequest() {
        return Result.badrequest();
    }

    /**
     * 无权限访问
     * @return
     */
    protected Result forbid() {
        return Result.fail(CodeMsg.NO_PERMISSION);
    }

    /**
     * 执行失败
     * @return
     */
    protected Result fail() {
        return Result.fail();
    }

    /**
     * 执行失败，返回自定义错误信息
     * @param msg
     * @return
     */
    protected Result fail(CodeMsg msg) {
        return Result.fail(msg);
    }

    /**
     * 执行失败，返回自定义错误
     * @param code
     * @param msg
     * @return
     */
    protected Result fail(int code, String msg) {
        return Result.fail(code, msg);
    }


    /**
     * 分页返回结果
     * @param response
     * @param data
     * @return
     */
//    protected Result ok(HttpServletResponse response, PagingData data) {
//        return Result.setPageResult(response, data);
//    }


}
